package com.heima.controller;

import cn.hutool.core.convert.Convert;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.service.SearchArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;


/**
 * @author chenshan
 */
@RestController
@RequestMapping("api/v1/history")
public class SearchHistoryController {

    @Autowired
    private SearchArticleService searchService;

    @PostMapping("load")
    public ResponseResult loadSearchHistory(HttpServletRequest request) throws IOException {
        return searchService.loadSearchHistory(request.getHeader("id"));
    }

    @PostMapping("del")
    public ResponseResult delSearchHistory(@RequestBody Map param, HttpServletRequest request) throws IOException {
        return searchService.delSearchHistory(Convert.toStr(param.get("id")));
    }

}
